package com.sky.aspect;

import com.sky.annotation.Permission;
import com.sky.context.BaseContext;
import com.sky.mapper.CheckPermission3;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Aspect
@Component
public class SelectPermission {
    @Resource
    CheckPermission3 checkPermission3;

    @Before("@annotation(com.sky.annotation.Permission)")
    public void checkPermission(JoinPoint joinPoint) throws RuntimeException {
        Long currentId = BaseContext.getCurrentId();
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Permission annotation = signature.getMethod().getAnnotation(Permission.class);
        String value = annotation.Value();
        List<String> check = checkPermission3.check(currentId);

            if (!check.contains(value)) {
                throw new RuntimeException("权限不足！！！");
            }





    }
}

